package com.colbby.datahouse.database;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.colbby.datahouse.entity.Member;
import com.colbby.datahouse.entity.Trade;

public class ObjectInserter implements Inserter<Object> {

	private static final ObjectInserter instance = new ObjectInserter();
	Map<Class<?>, Inserter<?>> inserterMap = new HashMap<>();
	
	private static final Logger logger = LoggerFactory.getLogger(ObjectInserter.class);
	
	private ObjectInserter() {}
		
	{
		inserterMap.put(Trade.class, new TradeInserter());
		inserterMap.put(Member.class, new MemberInserter());
	}
	
	public static ObjectInserter instance() {
		return instance;
	}
	
	@Override
	public void insert(Object entity) {
		Class<?> clazz = entity.getClass();
		Inserter in = inserterMap.get(clazz);
		if(in == null) {
			logger.info("找不到入库程序：" + entity.toString());
		}
		in.insert(entity);
	}
}
